#include "cCalibrate.h"

cCalibrate::cCalibrate( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxFrame( parent, id, title, pos, size, style )
{
	this->SetSizeHints( wxDefaultSize, wxDefaultSize );
	
	menuBar = new wxMenuBar( 0 );
	fileMenu = new wxMenu();
	wxMenuItem* exitMenuItem;
	exitMenuItem = new wxMenuItem( fileMenu, wxID_ANY, wxString( wxT("Exit") ) , wxEmptyString, wxITEM_NORMAL );
	fileMenu->Append( exitMenuItem );
	
	menuBar->Append( fileMenu, wxT("File") ); 
	
	this->SetMenuBar( menuBar );
	
	wxBoxSizer* bSizer2;
	bSizer2 = new wxBoxSizer( wxHORIZONTAL );
	
	imgPanel = new wxPanel( this, wxID_IMGPANEL, wxDefaultPosition, wxSize( 640,480 ), wxTAB_TRAVERSAL );
	bSizer2->Add( imgPanel, 1, wxEXPAND | wxALL, 5 );
	
	configPanel = new wxPanel( this, wxID_CONFIGPANEL, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
	wxFlexGridSizer* fgSizer1;
	fgSizer1 = new wxFlexGridSizer( 2, 2, 5, 0 );
	fgSizer1->SetFlexibleDirection( wxBOTH );
	fgSizer1->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
	
	calibrateButton = new wxButton( configPanel, wxID_ANY, wxT("Calibrate"), wxDefaultPosition, wxDefaultSize, 0 );
	fgSizer1->Add( calibrateButton, 0, wxALL, 5 );
	
	m_staticText37 = new wxStaticText( configPanel, wxID_ANY, wxT("Calibrate Stereo Camera"), wxDefaultPosition, wxDefaultSize, 0 );
	m_staticText37->Wrap( -1 );
	fgSizer1->Add( m_staticText37, 0, wxALL, 5 );
	
	calibDirPicker = new wxDirPickerCtrl( configPanel, wxID_CALIBDIRPICKER, wxEmptyString, wxT("Select a folder"), wxDefaultPosition, wxDefaultSize, wxDIRP_DEFAULT_STYLE|wxDIRP_DIR_MUST_EXIST );
	fgSizer1->Add( calibDirPicker, 0, wxALL, 5 );
	
	m_staticText3 = new wxStaticText( configPanel, wxID_ANY, wxT("Chess Boards Imgs Dir."), wxDefaultPosition, wxDefaultSize, 0 );
	m_staticText3->Wrap( -1 );
	fgSizer1->Add( m_staticText3, 0, wxALL, 5 );
	
	horizontalTextCtrl = new wxTextCtrl( configPanel, wxID_HORIZONTALTEXTCTRL, wxT("8"), wxDefaultPosition, wxDefaultSize, 0 );
	fgSizer1->Add( horizontalTextCtrl, 0, wxALL, 5 );
	
	m_staticText1 = new wxStaticText( configPanel, wxID_ANY, wxT("Horizontal Points"), wxDefaultPosition, wxDefaultSize, 0 );
	m_staticText1->Wrap( -1 );
	fgSizer1->Add( m_staticText1, 0, wxALL, 5 );
	
	verticalTextCtrl = new wxTextCtrl( configPanel, wxID_VERTICALTEXTCTRL, wxT("6"), wxPoint( 200,200 ), wxDefaultSize, 0 );
	fgSizer1->Add( verticalTextCtrl, 0, wxALL, 5 );
	
	m_staticText2 = new wxStaticText( configPanel, wxID_ANY, wxT("Vertical Points"), wxDefaultPosition, wxDefaultSize, 0 );
	m_staticText2->Wrap( -1 );
	fgSizer1->Add( m_staticText2, 0, wxALL, 5 );
	
	m_staticline2 = new wxStaticLine( configPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
	fgSizer1->Add( m_staticline2, 0, wxEXPAND | wxALL, 5 );
	
	m_staticline3 = new wxStaticLine( configPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
	fgSizer1->Add( m_staticline3, 0, wxEXPAND | wxALL, 5 );
	
	m_staticText6 = new wxStaticText( configPanel, wxID_ANY, wxT("Where to save results:"), wxDefaultPosition, wxDefaultSize, 0 );
	m_staticText6->Wrap( -1 );
	fgSizer1->Add( m_staticText6, 0, wxALL, 5 );
	
	
	fgSizer1->Add( 0, 0, 1, wxEXPAND, 5 );
	
	extrinTextCtrl = new wxTextCtrl( configPanel, wxID_ANY, wxT("extrinsics.yml"), wxDefaultPosition, wxDefaultSize, 0 );
	fgSizer1->Add( extrinTextCtrl, 0, wxALL, 5 );
	
	m_staticText5 = new wxStaticText( configPanel, wxID_ANY, wxT("Extrinsics file name"), wxDefaultPosition, wxDefaultSize, 0 );
	m_staticText5->Wrap( -1 );
	fgSizer1->Add( m_staticText5, 0, wxALL, 5 );
	
	intrinTextCtrl = new wxTextCtrl( configPanel, wxID_ANY, wxT("intrinsics.yml"), wxDefaultPosition, wxDefaultSize, 0 );
	fgSizer1->Add( intrinTextCtrl, 0, wxALL, 5 );
	
	m_staticText4 = new wxStaticText( configPanel, wxID_ANY, wxT("Intrinsics file name"), wxDefaultPosition, wxDefaultSize, 0 );
	m_staticText4->Wrap( -1 );
	fgSizer1->Add( m_staticText4, 0, wxALL, 5 );
	
	m_staticline4 = new wxStaticLine( configPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
	fgSizer1->Add( m_staticline4, 0, wxEXPAND | wxALL, 5 );
	
	m_staticline5 = new wxStaticLine( configPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
	fgSizer1->Add( m_staticline5, 0, wxEXPAND | wxALL, 5 );
	
	showImgsCheckBox = new wxCheckBox( configPanel, wxID_SHOWIMGSCHECKBOX, wxT("Show Images"), wxDefaultPosition, wxDefaultSize, 0 );
	showImgsCheckBox->SetValue(true); 
	fgSizer1->Add( showImgsCheckBox, 0, wxALL, 5 );
	
	wxString methodRadioBoxChoices[] = { wxT("Bouguet"), wxT("Hartley 1"), wxT("Hartley 2") };
	int methodRadioBoxNChoices = sizeof( methodRadioBoxChoices ) / sizeof( wxString );
	methodRadioBox = new wxRadioBox( configPanel, wxID_METHODRADIOBOX, wxT("Method"), wxDefaultPosition, wxDefaultSize, methodRadioBoxNChoices, methodRadioBoxChoices, 3, wxRA_SPECIFY_ROWS );
	methodRadioBox->SetSelection( 0 );
	fgSizer1->Add( methodRadioBox, 0, wxALL, 5 );
	
	configPanel->SetSizer( fgSizer1 );
	configPanel->Layout();
	fgSizer1->Fit( configPanel );
	bSizer2->Add( configPanel, 1, wxEXPAND | wxALL, 5 );
	
	this->SetSizer( bSizer2 );
	this->Layout();
	bSizer2->Fit( this );
	calibrateStatusBar = this->CreateStatusBar( 1, wxST_SIZEGRIP, wxID_ANY );
	
	this->Centre( wxBOTH );
	
	// Connect Events
	this->Connect( exitMenuItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( cCalibrate::onExit ) );
	calibrateButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( cCalibrate::onCalibrate ), NULL, this );
}

cCalibrate::~cCalibrate()
{
	// Disconnect Events
	this->Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( cCalibrate::onExit ) );
	calibrateButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( cCalibrate::onCalibrate ), NULL, this );
	
}